package com.cet.juc.java并发编程实战.第二章;

import java.util.concurrent.TimeUnit;

/**
 * @program: cet-practice
 * @description: 可重入锁测试
 * @author: 陈恩涛
 * @create: 2023-07-08 11:16
 **/
public class ReentrantLockTest {

    public static void main(String[] args) {
        Child child = new Child();
        // 仅仅当前实例枷锁
        child.doSomething();
        child.doSomethingElse();

    }
}

class Parent{
    public synchronized void doSomething() {
        System.out.println("我是你爹");
    }
}

class Child extends Parent{

    public  synchronized void doSomething() {
        System.out.println("我是您儿子");

        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }

        super.doSomething();
    }

    public synchronized void doSomethingElse() {
        System.out.println("巴拉巴拉");
    }
}
